import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/new_project.vue'
import funcs from "@/assets/overflow_y";

Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        redirect: {
            name: "Home"
        }
    },
    {
        path: '/test2',
        name: "Test",
        component: () => import("../views/Home.vue")
    },
    {
        path: '/home',
        name: 'Home',
        component: Home
    },
    {
        path: '/login',
        name: 'Login',
        component: () => import("../views/login.vue"),
        beforeEnter(_to, _from, _next) {
            if (_to.path == "/login" && _from != "/login") {

                delete localStorage["token"];
                delete localStorage["username"]
            }
            _next()
        }
    },
    {
        path: '/user',
        name: 'User',
        component: () => import("../views/UserHome.vue"),
    },
    {
        path: "/create",
        name: "CreateProject",
        component: () => import("../views/createGameProject.vue")
    }
]

const router = new VueRouter({
    base: process.env.BASE_URL,
    routes
})

router.beforeEach(
    (t, f, n) => {
        window.scrollTo(0, 0)
        funcs.funcs.hidden() // 默认每次跳转都隐藏滑块
        n();
    }
)
export default router
